home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfontdialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  17.5 KB  |  505 lines

  1. /*
  2.     $Id: kfontdialog.h 465272 2005-09-29 09:47:40Z mueller $
  3.  
  4.     Requires the Qt widget libraries, available at no cost at
  5.     http://www.troll.no
  6.  
  7.     Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@kde.org>
  8.     Copyright (c) 1999 Preston Brown <pbrown@kde.org>
  9.     Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
  10.  
  11.     This library is free software; you can redistribute it and/or
  12.     modify it under the terms of the GNU Library General Public
  13.     License as published by the Free Software Foundation; either
  14.     version 2 of the License, or (at your option) any later version.
  15.  
  16.     This library is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.     Library General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU Library General Public License
  22.     along with this library; see the file COPYING.LIB.  If not, write to
  23.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24.     Boston, MA 02110-1301, USA.
  25. */
  26. #ifndef _K_FONT_DIALOG_H_
  27. #define _K_FONT_DIALOG_H_
  28.  
  29. #include <qlineedit.h>
  30. #include <qbutton.h>
  31. #include <kdialogbase.h>
  32.  
  33. class QComboBox;
  34. class QCheckBox;
  35. class QFont;
  36. class QGroupBox;
  37. class QLabel;
  38. class QStringList;
  39. class KListBox;
  40. class KIntNumInput;
  41. /**
  42.  * @short A font selection widget.
  43.  *
  44.  * While KFontChooser as an ordinary widget can be embedded in
  45.  * custom dialogs and therefore is very flexible, in most cases
  46.  * it is preferable to use the convenience functions in
  47.  * KFontDialog.
  48.  *
  49.  * \image html kfontchooser.png "KDE Font Chooser"
  50.  *
  51.  * @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
  52.  * @version $Id: kfontdialog.h 465272 2005-09-29 09:47:40Z mueller $
  53.  */
  54. class KDEUI_EXPORT KFontChooser : public QWidget
  55. {
  56.   Q_OBJECT
  57.   Q_PROPERTY( QFont font READ font WRITE setFont )
  58.  
  59. public:
  60.   /**
  61.    *  @li @p FamilyList - Identifies the family (leftmost) list.
  62.    *  @li @p StyleList -  Identifies the style (center) list.
  63.    *  @li @p SizeList -   Identifies the size (rightmost) list.
  64.    */
  65.   enum FontColumn { FamilyList=0x01, StyleList=0x02, SizeList=0x04};
  66.  
  67.   /**
  68.    *  @li @p FontDiffFamily - Identifies a requested change in the font family.
  69.    *  @li @p FontDiffStyle -  Identifies a requested change in the font style.
  70.    *  @li @p FontDiffSize -   Identifies a requested change in the font size.
  71.    */
  72.   enum FontDiff { FontDiffFamily=0x01, FontDiffStyle=0x02, FontDiffSize=0x04 };
  73.  
  74.   /**
  75.    * Constructs a font picker widget.
  76.    * It normally comes up with all font families present on the system; the
  77.    * getFont method below does allow some more fine-tuning of the selection of fonts
  78.    * that will be displayed in the dialog.
  79.    * <p>Consider the following code snippet;
  80.    * \code
  81.    *    QStringList list;
  82.    *    KFontChooser::getFontList(list,SmoothScalableFonts);
  83.    *    KFontChooser chooseFont = new KFontChooser(0, "FontList", false, list);
  84.    * \endcode
  85.    * <p>
  86.    * The above creates a font chooser dialog with only SmoothScaleble fonts.
  87.    *
  88.    * @param parent The parent widget.
  89.    * @param name The widget name.
  90.    * @param onlyFixed Only display fonts which have fixed-width
  91.    *        character sizes.
  92.    * @param fontList A list of fonts to display, in XLFD format.  If
  93.    *        no list is formatted, the internal KDE font list is used.
  94.    *        If that has not been created, X is queried, and all fonts
  95.    *        available on the system are displayed.
  96.    * @param diff Display the difference version dialog.
  97.    *        See KFontDialog::getFontDiff().
  98.    * @param makeFrame Draws a frame with titles around the contents.
  99.    * @param visibleListSize The minimum number of visible entries in the
  100.    *        fontlists.
  101.    * @param sizeIsRelativeState If not zero the widget will show a
  102.    *        checkbox where the user may choose whether the font size
  103.    *        is to be interpreted as relative size.
  104.    *        Initial state of this checkbox will be set according to
  105.    *        *sizeIsRelativeState, user choice may be retrieved by
  106.    *        calling sizeIsRelative().
  107.    */
  108.   KFontChooser(QWidget *parent = 0L, const char *name = 0L,
  109.            bool onlyFixed = false,
  110.            const QStringList &fontList = QStringList(),
  111.            bool makeFrame = true, int visibleListSize=8,
  112.                bool diff = false, QButton::ToggleState *sizeIsRelativeState = 0L );
  113.  
  114.   /**
  115.    * Destructs the font chooser.
  116.    */
  117.   virtual ~KFontChooser();
  118.  
  119.   /**
  120.    * Enables or disable a font column in the chooser.
  121.    *
  122.    * Use this
  123.    * function if your application does not need or supports all font
  124.    * properties.
  125.    *
  126.    * @param column Specify the columns. An or'ed combination of
  127.    *        @p FamilyList, @p StyleList and @p SizeList is possible.
  128.    * @param state If @p false the columns are disabled.
  129.    */
  130.   void enableColumn( int column, bool state );
  131.  
  132.   /**
  133.    * Sets the currently selected font in the chooser.
  134.    *
  135.    * @param font The font to select.
  136.    * @param onlyFixed Readjust the font list to display only fixed
  137.    *        width fonts if @p true, or vice-versa.
  138.    */
  139.   void setFont( const QFont &font, bool onlyFixed = false );
  140.  
  141.   /**
  142.    * @return The bitmask corresponding to the attributes the user
  143.    *         wishes to change.
  144.    */
  145.   int fontDiffFlags();
  146.  
  147.   /**
  148.    * @return The currently selected font in the chooser.
  149.    */
  150.   QFont font() const { return selFont; }
  151.  
  152.   /**
  153.    * Sets the color to use in the preview.
  154.    */
  155.   void setColor( const QColor & col );
  156.  
  157.   /**
  158.    * @return The color currently used in the preview (default: the text
  159.    *         color of the active color group)
  160.    */
  161.   QColor color() const;
  162.  
  163.   /**
  164.    * Sets the background color to use in the preview.
  165.    */
  166.   void setBackgroundColor( const QColor & col );
  167.  
  168.   /**
  169.    * @return The background color currently used in the preview (default:
  170.    *         the base color of the active colorgroup)
  171.    */
  172.   QColor backgroundColor() const;
  173.  
  174.   /**
  175.    * Sets the state of the checkbox indicating whether the font size
  176.    * is to be interpreted as relative size.
  177.    * NOTE: If parameter sizeIsRelative was not set in the constructor
  178.    *       of the widget this setting will be ignored.
  179.    */
  180.   void setSizeIsRelative( QButton::ToggleState relative );
  181.  
  182.   /**
  183.    * @return Whether the font size is to be interpreted as relative size
  184.    *         (default: QButton:Off)
  185.    */
  186.   QButton::ToggleState sizeIsRelative() const;
  187.  
  188.  
  189.   /**
  190.    * @return The current text in the sample text input area.
  191.    */
  192.   QString sampleText() const { return sampleEdit->text(); }
  193.  
  194.   /**
  195.    * Sets the sample text.
  196.    *
  197.    * Normally you should not change this
  198.    * text, but it can be better to do this if the default text is
  199.    * too large for the edit area when using the default font of your
  200.    * application.
  201.    *
  202.    * @param text The new sample text. The current will be removed.
  203.    */
  204.   void setSampleText( const QString &text )
  205.   {
  206.     sampleEdit->setText( text );
  207.   }
  208.  
  209.   /**
  210.    * Shows or hides the sample text box.
  211.    *
  212.    * @param visible Set it to true to show the box, to false to hide it.
  213.    * @since 3.5
  214.    */
  215.   void setSampleBoxVisible( bool visible )
  216.   {
  217.     sampleEdit->setShown( visible );
  218.   }
  219.  
  220.   /**
  221.    * Converts a QFont into the corresponding X Logical Font
  222.    * Description (XLFD).
  223.    *
  224.    * @param theFont The font to convert.
  225.    * @return A string representing the given font in XLFD format.
  226.    */
  227.   static QString getXLFD( const QFont &theFont )
  228.     { return theFont.rawName(); }
  229.  
  230.   /**
  231.    * The selection criteria for the font families shown in the dialog.
  232.    *  @li @p FixedWidthFont when included only fixed-width fonts are returned.
  233.    *        The fonts where the width of every character is equal.
  234.    *  @li @p ScalableFont when included only scalable fonts are returned;
  235.    *        certain configurations allow bitmap fonts to remain unscaled and
  236.    *        thus these fonts have limited number of sizes.
  237.    *  @li @p SmoothScalableFont when included only return smooth scalable fonts.
  238.    *        this will return only non-bitmap fonts which are scalable to any size requested.
  239.    *        Setting this option to true will mean the "scalable" flag is irrelavant.
  240.    */
  241.   enum FontListCriteria { FixedWidthFonts=0x01, ScalableFonts=0x02, SmoothScalableFonts=0x04 };
  242.  
  243.   /**
  244.    * Creates a list of font strings.
  245.    *
  246.    * @param list The list is returned here.
  247.    * @param fontListCriteria should contain all the restrictions for font selection as OR-ed values
  248.    *        @see KFontChooser::FontListCriteria for the individual values
  249.    */
  250.   static void getFontList( QStringList &list, uint fontListCriteria);
  251.  
  252.   /**
  253.    * Reimplemented for internal reasons.
  254.    */
  255.   virtual QSize sizeHint( void ) const;
  256.  
  257. signals:
  258.   /**
  259.    * Emitted whenever the selected font changes.
  260.    */
  261.   void fontSelected( const QFont &font );
  262.  
  263. private slots:
  264.   void toggled_checkbox();
  265.   void family_chosen_slot(const QString&);
  266.   void size_chosen_slot(const QString&);
  267.   void style_chosen_slot(const QString&);
  268.   void displaySample(const QFont &font);
  269.   void showXLFDArea(bool);
  270.   void size_value_slot(int);
  271. private:
  272.   void fillFamilyListBox(bool onlyFixedFonts = false);
  273.   void fillSizeList();
  274.   // This one must be static since getFontList( QStringList, char*) is so
  275.   static void addFont( QStringList &list, const char *xfont );
  276.  
  277.   void setupDisplay();
  278.  
  279.   // pointer to an optinally supplied list of fonts to
  280.   // inserted into the fontdialog font-family combo-box
  281.   QStringList  fontList;
  282.  
  283.   KIntNumInput *sizeOfFont;
  284.  
  285.   QLineEdit    *sampleEdit;
  286.   QLineEdit    *xlfdEdit;
  287.  
  288.   QLabel       *familyLabel;
  289.   QLabel       *styleLabel;
  290.   QCheckBox    *familyCheckbox;
  291.   QCheckBox    *styleCheckbox;
  292.   QCheckBox    *sizeCheckbox;
  293.   QLabel       *sizeLabel;
  294.   KListBox     *familyListBox;
  295.   KListBox     *styleListBox;
  296.   KListBox     *sizeListBox;
  297.   QComboBox    *charsetsCombo; // BIC: remove in KDE4
  298.   QCheckBox    *sizeIsRelativeCheckBox;
  299.  
  300.   QFont        selFont;
  301.  
  302.   QString      selectedStyle;
  303.   int          selectedSize;
  304.   QMap<QString, QString> currentStyles;
  305.  
  306.   bool usingFixed;
  307.  
  308. protected:
  309.   virtual void virtual_hook( int id, void* data );
  310. private:
  311.   class KFontChooserPrivate;
  312.   KFontChooserPrivate *d;
  313. };
  314.  
  315. /**
  316.  * @short A font selection dialog.
  317.  *
  318.  * The KFontDialog provides a dialog for interactive font selection.
  319.  * It is basically a thin wrapper around the KFontChooser widget,
  320.  * which can also be used standalone. In most cases, the simplest
  321.  * use of this class is the static method KFontDialog::getFont(),
  322.  * which pops up the dialog, allows the user to select a font, and
  323.  * returns when the dialog is closed.
  324.  *
  325.  * Example:
  326.  *
  327.  * \code
  328.  *      QFont myFont;
  329.  *      int result = KFontDialog::getFont( myFont );
  330.  *      if ( result == KFontDialog::Accepted )
  331.  *            ...
  332.  * \endcode
  333.  *
  334.  * \image html kfontdialog.png "KDE Font Dialog"
  335.  *
  336.  * @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
  337.  * @version $Id: kfontdialog.h 465272 2005-09-29 09:47:40Z mueller $
  338.  */
  339. class KDEUI_EXPORT KFontDialog : public KDialogBase  {
  340.     Q_OBJECT
  341.  
  342. public:
  343.   /**
  344.    * Constructs a font selection dialog.
  345.    *
  346.    * @param parent The parent widget of the dialog, if any.
  347.    * @param name The name of the dialog.
  348.    * @param modal Specifies whether the dialog is modal or not.
  349.    * @param onlyFixed only display fonts which have fixed-width
  350.    *        character sizes.
  351.    * @param fontlist a list of fonts to display, in XLFD format.  If
  352.    *        no list is formatted, the internal KDE font list is used.
  353.    *        If that has not been created, X is queried, and all fonts
  354.    *        available on the system are displayed.
  355.    * @param makeFrame Draws a frame with titles around the contents.
  356.    * @param diff Display the difference version dialog. See getFontDiff().
  357.    * @param sizeIsRelativeState If not zero the widget will show a
  358.    *        checkbox where the user may choose whether the font size
  359.    *        is to be interpreted as relative size.
  360.    *        Initial state of this checkbox will be set according to
  361.    *        *sizeIsRelativeState, user choice may be retrieved by
  362.    *        calling sizeIsRelative().
  363.    *
  364.    */
  365.   KFontDialog( QWidget *parent = 0L, const char *name = 0,
  366.            bool onlyFixed = false, bool modal = false,
  367.            const QStringList &fontlist = QStringList(),
  368.            bool makeFrame = true, bool diff = false,
  369.                QButton::ToggleState *sizeIsRelativeState = 0L );
  370.  
  371.   /**
  372.    * Sets the currently selected font in the dialog.
  373.    *
  374.    * @param font The font to select.
  375.    * @param onlyFixed readjust the font list to display only fixed
  376.    *        width fonts if true, or vice-versa
  377.    */
  378.   void setFont( const QFont &font, bool onlyFixed = false )
  379.     { chooser->setFont(font, onlyFixed); }
  380.  
  381.   /**
  382.    * @return The currently selected font in the dialog.
  383.    */
  384.   QFont font() const { return chooser->font(); }
  385.  
  386.   /**
  387.    * Sets the state of the checkbox indicating whether the font size
  388.    * is to be interpreted as relative size.
  389.    * NOTE: If parameter sizeIsRelative was not set in the constructor
  390.    *       of the dialog this setting will be ignored.
  391.    */
  392.   void setSizeIsRelative( QButton::ToggleState relative )
  393.     { chooser->setSizeIsRelative( relative ); }
  394.  
  395.   /**
  396.    * @return Whether the font size is to be interpreted as relative size
  397.    *         (default: false)
  398.    */
  399.   QButton::ToggleState sizeIsRelative() const
  400.     { return chooser->sizeIsRelative(); }
  401.  
  402.   /**
  403.    * Creates a modal font dialog, lets the user choose a font,
  404.    * and returns when the dialog is closed.
  405.    *
  406.    * @param theFont a reference to the font to write the chosen font
  407.    *        into.
  408.    * @param onlyFixed if true, only select from fixed-width fonts.
  409.    * @param parent Parent widget of the dialog. Specifying a widget different
  410.    *        from 0 (Null) improves centering (looks better).
  411.    * @param makeFrame Draws a frame with titles around the contents.
  412.    * @param sizeIsRelativeState If not zero the widget will show a
  413.    *        checkbox where the user may choose whether the font size
  414.    *        is to be interpreted as relative size.
  415.    *        Initial state of this checkbox will be set according to
  416.    *        *sizeIsRelativeState and user choice will be returned
  417.    *        therein.
  418.    *
  419.    * @return QDialog::result().
  420.    */
  421.   static int getFont( QFont &theFont, bool onlyFixed = false,
  422.               QWidget *parent = 0L, bool makeFrame = true,
  423.                       QButton::ToggleState *sizeIsRelativeState = 0L );
  424.  
  425.   /**
  426.    * Creates a modal font difference dialog, lets the user choose a selection
  427.    * of changes that should be made to a set of fonts, and returns when the
  428.    * dialog is closed. Useful for choosing slight adjustments to the font set
  429.    * when the user would otherwise have to manually edit a number of fonts.
  430.    *
  431.    * @param theFont a reference to the font to write the chosen font
  432.    *        into.
  433.    * @param diffFlags a reference to the int into which the chosen
  434.    *        difference selection bitmask should be written.
  435.    *        Check the returned bitmask like:
  436.    *        \code
  437.    *        if ( diffFlags & KFontChooser::FontDiffFamily )
  438.    *            [...]
  439.    *        if ( diffFlags & KFontChooser::FontDiffStyle )
  440.    *            [...]
  441.    *        if ( diffFlags & KFontChooser::FontDiffSize )
  442.    *            [...]
  443.    *        \endcode
  444.    * @param onlyFixed if true, only select from fixed-width fonts.
  445.    * @param parent Parent widget of the dialog. Specifying a widget different
  446.    *        from 0 (Null) improves centering (looks better).
  447.    * @param makeFrame Draws a frame with titles around the contents.
  448.    * @param sizeIsRelativeState If not zero the widget will show a
  449.    *        checkbox where the user may choose whether the font size
  450.    *        is to be interpreted as relative size.
  451.    *        Initial state of this checkbox will be set according to
  452.    *        *sizeIsRelativeState and user choice will be returned
  453.    *        therein.
  454.    *
  455.    * @returns QDialog::result().
  456.    */
  457.   static int getFontDiff( QFont &theFont, int &diffFlags, bool onlyFixed = false,
  458.               QWidget *parent = 0L, bool makeFrame = true,
  459.                       QButton::ToggleState *sizeIsRelativeState = 0L );
  460.  
  461.   /**
  462.    * When you are not only interested in the font selected, but also
  463.    * in the example string typed in, you can call this method.
  464.    *
  465.    * @param theFont a reference to the font to write the chosen font
  466.    *        into.
  467.    * @param theString a reference to the example text that was typed.
  468.    * @param onlyFixed if true, only select from fixed-width fonts.
  469.    * @param parent Parent widget of the dialog. Specifying a widget different
  470.    *        from 0 (Null) improves centering (looks better).
  471.    * @param makeFrame Draws a frame with titles around the contents.
  472.    * @param sizeIsRelativeState If not zero the widget will show a
  473.    *        checkbox where the user may choose whether the font size
  474.    *        is to be interpreted as relative size.
  475.    *        Initial state of this checkbox will be set according to
  476.    *        *sizeIsRelativeState and user choice will be returned
  477.    *        therein.
  478.    * @return The result of the dialog.
  479.    */
  480.   static int getFontAndText( QFont &theFont, QString &theString,
  481.                  bool onlyFixed = false, QWidget *parent = 0L,
  482.                  bool makeFrame = true,
  483.                              QButton::ToggleState *sizeIsRelativeState = 0L );
  484.  
  485. signals:
  486.   /**
  487.    * Emitted whenever the currently selected font changes.
  488.    * Connect to this to monitor the font as it is selected if you are
  489.    * not running modal.
  490.    */
  491.   void fontSelected( const QFont &font );
  492.  
  493. protected:
  494.   KFontChooser *chooser;
  495.  
  496. protected:
  497.   virtual void virtual_hook( int id, void* data );
  498. private:
  499.   class KFontDialogPrivate;
  500.   KFontDialogPrivate *d;
  501.  
  502. };
  503.  
  504. #endif
  505.